home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 58 / pcpp58a.iso / extras / quake 3 source / Q3A_ToolSource.exe / Main / WIN_DLG.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-02  |  13.9 KB  |  596 lines

  1. #include "stdafx.h"
  2. #include "qe3.h"
  3. #include "PrefsDlg.h"
  4.  
  5. BOOL CALLBACK EditCommandDlgProc (
  6.     HWND hwndDlg,    // handle to dialog box
  7.     UINT uMsg,    // message
  8.     WPARAM wParam,    // first message parameter
  9.     LPARAM lParam     // second message parameter
  10.    )
  11. {
  12.     char    key[1024];
  13.     char    value[1024];
  14.     char    *temp;
  15.     int        index;
  16.     HWND    hOwner;
  17.     
  18.     hOwner = GetParent (hwndDlg);
  19.  
  20.     switch (uMsg)
  21.     {
  22.     case WM_INITDIALOG:
  23.         index = SendDlgItemMessage (hOwner, IDC_CMD_LIST, LB_GETCURSEL, 0, 0);
  24.     if (index >= 0)
  25.     {
  26.           SendDlgItemMessage(hOwner, IDC_CMD_LIST, LB_GETTEXT, index, (LPARAM) (LPCTSTR) key);
  27.           temp = ValueForKey (g_qeglobals.d_project_entity, key);
  28.           strcpy (value, temp);
  29.           SetDlgItemText(hwndDlg, IDC_CMDMENUTEXT, key);
  30.           SetDlgItemText(hwndDlg, IDC_CMDCOMMAND, value);
  31.     }
  32.         return FALSE;
  33.         break;
  34.  
  35.     case WM_COMMAND: 
  36.         switch (LOWORD(wParam)) 
  37.         { 
  38.             case IDOK:
  39.                 if (!GetDlgItemText(hwndDlg, IDC_CMDMENUTEXT, key, 64))
  40.                 {
  41.                     Sys_Printf ("Command not added\n");
  42.                     return FALSE;
  43.                 }
  44.  
  45.                 if (!GetDlgItemText(hwndDlg, IDC_CMDCOMMAND, value, 64))
  46.                 {
  47.                     Sys_Printf ("Command not added\n");
  48.                     return FALSE;
  49.                 }
  50.  
  51.                 //if (key[0] == 'b' && key[1] == 's' && key[2] == 'p')
  52.                 //{
  53.                     SetKeyValue (g_qeglobals.d_project_entity, key, value);
  54.                     FillBSPMenu ();
  55.                 //}
  56.                 //else
  57.                 //    Sys_Printf ("BSP commands must be preceded by \"bsp\"");
  58.  
  59.                 EndDialog(hwndDlg, 1);
  60.                 return TRUE;
  61.  
  62.             case IDCANCEL:
  63.                 EndDialog(hwndDlg, 0);
  64.                 return TRUE;
  65.         }
  66.     }
  67.     return FALSE;
  68. }
  69.  
  70. BOOL CALLBACK AddCommandDlgProc (
  71.     HWND hwndDlg,    // handle to dialog box
  72.     UINT uMsg,    // message
  73.     WPARAM wParam,    // first message parameter
  74.     LPARAM lParam     // second message parameter
  75.    )
  76. {
  77.     char    key[64];
  78.     char    value[128];
  79.  
  80.     switch (uMsg)
  81.     {
  82.     case WM_COMMAND: 
  83.         switch (LOWORD(wParam)) 
  84.         { 
  85.             case IDOK:
  86.                 if (!GetDlgItemText(hwndDlg, IDC_CMDMENUTEXT, key, 64))
  87.                 {
  88.                     Sys_Printf ("Command not added\n");
  89.                     return FALSE;
  90.                 }
  91.  
  92.                 if (!GetDlgItemText(hwndDlg, IDC_CMDCOMMAND, value, 64))
  93.                 {
  94.                     Sys_Printf ("Command not added\n");
  95.                     return FALSE;
  96.                 }
  97.  
  98.                 if (key[0] == 'b' && key[1] == 's' && key[2] == 'p')
  99.                 {
  100.                     SetKeyValue (g_qeglobals.d_project_entity, key, value);
  101.                     FillBSPMenu ();
  102.                 }
  103.                 else
  104.                     Sys_Printf ("BSP commands must be preceded by \"bsp\"");
  105.  
  106.                 EndDialog(hwndDlg, 1);
  107.                 return TRUE;
  108.  
  109.             case IDCANCEL:
  110.                 EndDialog(hwndDlg, 0);
  111.                 return TRUE;
  112.         }
  113.     }
  114.     return FALSE;
  115. }
  116.  
  117. void UpdateBSPCommandList (HWND hwndDlg)
  118. {
  119.     int            i;
  120.     epair_t        *ep;
  121.  
  122.     SendDlgItemMessage(hwndDlg, IDC_CMD_LIST, LB_RESETCONTENT, 0 , 0);
  123.  
  124.     i = 0;
  125.     for (ep = g_qeglobals.d_project_entity->epairs ; ep ; ep=ep->next)
  126.     {
  127.         if (ep->key[0] == 'b' && ep->key[1] == 's' && ep->key[2] == 'p')
  128.         {
  129.             SendDlgItemMessage(hwndDlg, IDC_CMD_LIST, LB_ADDSTRING, i , (LPARAM) ep->key);
  130.             i++;
  131.         }
  132.     }
  133. }
  134.  
  135.  
  136. // FIXME: turn this into an MFC dialog
  137. BOOL CALLBACK ProjectDlgProc (
  138.     HWND hwndDlg,    // handle to dialog box
  139.     UINT uMsg,    // message
  140.     WPARAM wParam,    // first message parameter
  141.     LPARAM lParam     // second message parameter
  142.    )
  143. {
  144.     char        key[1024];
  145.     char        value[1024];
  146.     int            index;
  147.  
  148.     switch (uMsg)
  149.     {
  150.     case WM_INITDIALOG:
  151.         SetDlgItemText(hwndDlg, IDC_PRJBASEPATH, ValueForKey (g_qeglobals.d_project_entity, "basepath"));
  152.         SetDlgItemText(hwndDlg, IDC_PRJMAPSPATH, ValueForKey (g_qeglobals.d_project_entity, "mapspath"));
  153.         SetDlgItemText(hwndDlg, IDC_PRJRSHCMD, ValueForKey (g_qeglobals.d_project_entity, "rshcmd"));
  154.         SetDlgItemText(hwndDlg, IDC_PRJREMOTEBASE, ValueForKey (g_qeglobals.d_project_entity, "remotebasepath"));
  155.         SetDlgItemText(hwndDlg, IDC_PRJENTITYPATH, ValueForKey (g_qeglobals.d_project_entity, "entitypath"));
  156.         SetDlgItemText(hwndDlg, IDC_PRJTEXPATH, ValueForKey (g_qeglobals.d_project_entity, "texturepath"));
  157.         UpdateBSPCommandList (hwndDlg);
  158.         // Timo
  159.         // additional fields
  160.         CheckDlgButton( hwndDlg, IDC_CHECK_BPRIMIT, (g_qeglobals.m_bBrushPrimitMode) ? BST_CHECKED : BST_UNCHECKED );
  161. //        SendMessage( ::GetDlgItem( hwndDlg, IDC_CHECK_BPRIMIT ), BM_SETCHECK, (WPARAM) g_qeglobals.m_bBrushPrimitMode, 0 );
  162.         return TRUE;
  163.  
  164.     case WM_COMMAND: 
  165.         switch (LOWORD(wParam)) 
  166.         { 
  167.             case IDC_ADDCMD:
  168. //                DialogBox(g_qeglobals.d_hInstance, (char *)IDD_ADDCMD, g_qeglobals.d_hwndMain, AddCommandDlgProc);
  169.                 DialogBox(g_qeglobals.d_hInstance, (char *)IDD_ADDCMD, hwndDlg, AddCommandDlgProc);
  170.                 UpdateBSPCommandList (hwndDlg);
  171.                 break;
  172.  
  173.             case IDC_EDITCMD:
  174. //                DialogBox(g_qeglobals.d_hInstance, (char *)IDD_ADDCMD, g_qeglobals.d_hwndMain, EditCommandDlgProc);
  175.                 DialogBox(g_qeglobals.d_hInstance, (char *)IDD_ADDCMD, hwndDlg, EditCommandDlgProc);
  176.                 UpdateBSPCommandList (hwndDlg);
  177.                 break;
  178.  
  179.             case IDC_REMCMD:
  180.                 index = SendDlgItemMessage (hwndDlg, IDC_CMD_LIST, LB_GETCURSEL, 0, 0);
  181.                 SendDlgItemMessage(hwndDlg, IDC_CMD_LIST, LB_GETTEXT, index, (LPARAM) (LPCTSTR) key);
  182.                 DeleteKey (g_qeglobals.d_project_entity, key);
  183.                 Sys_Printf ("Selected %d\n", index);
  184.                 UpdateBSPCommandList (hwndDlg);
  185.                 break;
  186.  
  187.             case IDOK:
  188.                 GetDlgItemText(hwndDlg, IDC_PRJBASEPATH, value, 1024);
  189.                 SetKeyValue (g_qeglobals.d_project_entity, "basepath", value);
  190.                 GetDlgItemText(hwndDlg, IDC_PRJMAPSPATH, value, 1024);
  191.                 SetKeyValue (g_qeglobals.d_project_entity, "mapspath", value);
  192.                 GetDlgItemText(hwndDlg, IDC_PRJRSHCMD, value, 1024);
  193.                 SetKeyValue (g_qeglobals.d_project_entity, "rshcmd", value);
  194.                 GetDlgItemText(hwndDlg, IDC_PRJREMOTEBASE, value, 1024);
  195.                 SetKeyValue (g_qeglobals.d_project_entity, "remotebasepath", value);
  196.                 GetDlgItemText(hwndDlg, IDC_PRJENTITYPATH, value, 1024);
  197.                 SetKeyValue (g_qeglobals.d_project_entity, "entitypath", value);
  198.                 GetDlgItemText(hwndDlg, IDC_PRJTEXPATH, value, 1024);
  199.                 SetKeyValue (g_qeglobals.d_project_entity, "texturepath", value);
  200.                 // Timo
  201.                 // read additional fields
  202.                 if ( IsDlgButtonChecked( hwndDlg, IDC_CHECK_BPRIMIT ) )
  203.                 {
  204.                     g_qeglobals.m_bBrushPrimitMode = TRUE;
  205.                 }
  206.                 else
  207.                 {
  208.                     g_qeglobals.m_bBrushPrimitMode = FALSE;
  209.                 }
  210.                 SetKeyValue ( g_qeglobals.d_project_entity, "brush_primit", ( g_qeglobals.m_bBrushPrimitMode ? "1" : "0" ) );
  211.  
  212.                 EndDialog(hwndDlg, 1);
  213.                 QE_SaveProject(g_strProject);
  214.                 return TRUE;
  215.  
  216.             case IDCANCEL:
  217.                 EndDialog(hwndDlg, 0);
  218.                 return TRUE;
  219.         }
  220.     }
  221.     return FALSE;
  222. }
  223.  
  224. void DoProjectSettings()
  225. {
  226.     DialogBox(g_qeglobals.d_hInstance, (char *)IDD_PROJECT, g_qeglobals.d_hwndMain, ProjectDlgProc);
  227. }
  228.  
  229.  
  230.  
  231. BOOL CALLBACK GammaDlgProc (
  232.     HWND hwndDlg,    // handle to dialog box
  233.     UINT uMsg,    // message
  234.     WPARAM wParam,    // first message parameter
  235.     LPARAM lParam     // second message parameter
  236.    )
  237. {
  238.     char sz[256];
  239.  
  240.     switch (uMsg)
  241.     {
  242.     case WM_INITDIALOG:
  243.         sprintf(sz, "%1.1f", g_qeglobals.d_savedinfo.fGamma);        
  244.         SetWindowText(GetDlgItem(hwndDlg, IDC_G_EDIT), sz);
  245.         return TRUE;
  246.     case WM_COMMAND: 
  247.         switch (LOWORD(wParam)) 
  248.         { 
  249.         
  250.         case IDOK:
  251.             GetWindowText(GetDlgItem(hwndDlg, IDC_G_EDIT), sz, 255);
  252.             g_qeglobals.d_savedinfo.fGamma = atof(sz);
  253.             EndDialog(hwndDlg, 1);
  254.             return TRUE;
  255.  
  256.         case IDCANCEL:
  257.             EndDialog(hwndDlg, 0);
  258.             return TRUE;
  259.         }
  260.     }
  261.     return FALSE;
  262. }
  263.  
  264.  
  265.  
  266. void DoGamma(void)
  267. {
  268.     if ( DialogBox(g_qeglobals.d_hInstance, (char *)IDD_GAMMA, g_qeglobals.d_hwndMain, GammaDlgProc))
  269.     {
  270.     }
  271. }        
  272.  
  273. //================================================
  274.  
  275.  
  276. void SelectBrush (int entitynum, int brushnum)
  277. {
  278.     entity_t    *e;
  279.     brush_t        *b;
  280.     int            i;
  281.  
  282.     if (entitynum == 0)
  283.         e = world_entity;
  284.     else
  285.     {
  286.         e = entities.next;
  287.         while (--entitynum)
  288.         {
  289.             e=e->next;
  290.             if (e == &entities)
  291.             {
  292.                 Sys_Status ("No such entity.", 0);
  293.                 return;
  294.             }
  295.         }
  296.     }
  297.  
  298.     b = e->brushes.onext;
  299.     if (b == &e->brushes)
  300.     {
  301.         Sys_Status ("No such brush.", 0);
  302.         return;
  303.     }
  304.     while (brushnum--)
  305.     {
  306.         b=b->onext;
  307.         if (b == &e->brushes)
  308.         {
  309.             Sys_Status ("No such brush.", 0);
  310.             return;
  311.         }
  312.     }
  313.  
  314.     Brush_RemoveFromList (b);
  315.     Brush_AddToList (b, &selected_brushes);
  316.  
  317.  
  318.     Sys_UpdateWindows (W_ALL);
  319.     for (i=0 ; i<3 ; i++)
  320.   {
  321.     if (g_pParentWnd->GetXYWnd())
  322.       g_pParentWnd->GetXYWnd()->GetOrigin()[i] = (b->mins[i] + b->maxs[i])/2;
  323.  
  324.     if (g_pParentWnd->GetXZWnd())
  325.       g_pParentWnd->GetXZWnd()->GetOrigin()[i] = (b->mins[i] + b->maxs[i])/2;
  326.     
  327.     if (g_pParentWnd->GetYZWnd())
  328.       g_pParentWnd->GetYZWnd()->GetOrigin()[i] = (b->mins[i] + b->maxs[i])/2;
  329.   }
  330.  
  331.     Sys_Status ("Selected.", 0);
  332. }
  333.  
  334. /*
  335. =================
  336. GetSelectionIndex
  337. =================
  338. */
  339. void GetSelectionIndex (int *ent, int *brush)
  340. {
  341.     brush_t        *b, *b2;
  342.     entity_t    *entity;
  343.  
  344.     *ent = *brush = 0;
  345.  
  346.     b = selected_brushes.next;
  347.     if (b == &selected_brushes)
  348.         return;
  349.  
  350.     // find entity
  351.     if (b->owner != world_entity)
  352.     {
  353.         (*ent)++;
  354.         for (entity = entities.next ; entity != &entities 
  355.             ; entity=entity->next, (*ent)++)
  356.         ;
  357.     }
  358.  
  359.     // find brush
  360.     for (b2=b->owner->brushes.onext 
  361.         ; b2 != b && b2 != &b->owner->brushes
  362.         ; b2=b2->onext, (*brush)++)
  363.     ;
  364. }
  365.  
  366. BOOL CALLBACK FindBrushDlgProc (
  367.     HWND hwndDlg,    // handle to dialog box
  368.     UINT uMsg,    // message
  369.     WPARAM wParam,    // first message parameter
  370.     LPARAM lParam     // second message parameter
  371.    )
  372. {
  373.     char entstr[256];
  374.     char brushstr[256];
  375.     HWND    h;
  376.     int        ent, brush;
  377.  
  378.     switch (uMsg)
  379.     {
  380.     case WM_INITDIALOG:
  381.         // set entity and brush number
  382.         GetSelectionIndex (&ent, &brush);
  383.         sprintf (entstr, "%i", ent);
  384.         sprintf (brushstr, "%i", brush);
  385.         SetWindowText(GetDlgItem(hwndDlg, IDC_FIND_ENTITY), entstr);
  386.         SetWindowText(GetDlgItem(hwndDlg, IDC_FIND_BRUSH), brushstr);
  387.  
  388.         h = GetDlgItem(hwndDlg, IDC_FIND_ENTITY);
  389.         SetFocus (h);
  390.         return FALSE;
  391.  
  392.     case WM_COMMAND: 
  393.         switch (LOWORD(wParam)) 
  394.         { 
  395.             case IDOK:
  396.                 GetWindowText(GetDlgItem(hwndDlg, IDC_FIND_ENTITY), entstr, 255);
  397.                 GetWindowText(GetDlgItem(hwndDlg, IDC_FIND_BRUSH), brushstr, 255);
  398.                 SelectBrush (atoi(entstr), atoi(brushstr));
  399.                 EndDialog(hwndDlg, 1);
  400.                 return TRUE;
  401.  
  402.             case IDCANCEL:
  403.                 EndDialog(hwndDlg, 0);
  404.                 return TRUE;
  405.         }    
  406.     }
  407.     return FALSE;
  408. }
  409.  
  410.  
  411.  
  412. void DoFind(void)
  413. {
  414.     DialogBox(g_qeglobals.d_hInstance, (char *)IDD_FINDBRUSH, g_qeglobals.d_hwndMain, FindBrushDlgProc);
  415. }    
  416.     
  417. /*
  418. ===================================================
  419.  
  420.   ARBITRARY ROTATE
  421.  
  422. ===================================================
  423. */
  424.  
  425.  
  426. BOOL CALLBACK RotateDlgProc (
  427.     HWND hwndDlg,    // handle to dialog box
  428.     UINT uMsg,    // message
  429.     WPARAM wParam,    // first message parameter
  430.     LPARAM lParam     // second message parameter
  431.    )
  432. {
  433.     char    str[256];
  434.     HWND    h;
  435.     float    v;
  436.  
  437.     switch (uMsg)
  438.     {
  439.     case WM_INITDIALOG:
  440.         h = GetDlgItem(hwndDlg, IDC_FIND_ENTITY);
  441.         SetFocus (h);
  442.         return FALSE;
  443.  
  444.     case WM_COMMAND: 
  445.         switch (LOWORD(wParam)) 
  446.         { 
  447.         
  448.         case IDOK:
  449.             GetWindowText(GetDlgItem(hwndDlg, IDC_ROTX), str, 255);
  450.             v = atof(str);
  451.             if (v)
  452.                 Select_RotateAxis (0, v);
  453.  
  454.             GetWindowText(GetDlgItem(hwndDlg, IDC_ROTY), str, 255);
  455.             v = atof(str);
  456.             if (v)
  457.                 Select_RotateAxis (1, v);
  458.  
  459.             GetWindowText(GetDlgItem(hwndDlg, IDC_ROTZ), str, 255);
  460.             v = atof(str);
  461.             if (v)
  462.                 Select_RotateAxis (2, v);
  463.  
  464.             EndDialog(hwndDlg, 1);
  465.             return TRUE;
  466.  
  467.         case IDCANCEL:
  468.             EndDialog(hwndDlg, 0);
  469.             return TRUE;
  470.         }    
  471.     }
  472.  
  473.     return FALSE;
  474. }
  475.  
  476.  
  477.  
  478. void DoRotate(void)
  479. {
  480.     DialogBox(g_qeglobals.d_hInstance, (char *)IDD_ROTATE, g_qeglobals.d_hwndMain, RotateDlgProc);
  481. }
  482.         
  483. /*
  484. ===================================================
  485.  
  486.   ARBITRARY SIDES
  487.  
  488. ===================================================
  489. */
  490.  
  491. bool g_bDoCone = false;
  492. bool g_bDoSphere = false;
  493. BOOL CALLBACK SidesDlgProc (
  494.     HWND hwndDlg,    // handle to dialog box
  495.     UINT uMsg,    // message
  496.     WPARAM wParam,    // first message parameter
  497.     LPARAM lParam     // second message parameter
  498.    )
  499. {
  500.     char str[256];
  501.     HWND    h;
  502.  
  503.     switch (uMsg)
  504.     {
  505.     case WM_INITDIALOG:
  506.         h = GetDlgItem(hwndDlg, IDC_SIDES);
  507.         SetFocus (h);
  508.         return FALSE;
  509.  
  510.     case WM_COMMAND: 
  511.         switch (LOWORD(wParam)) { 
  512.         
  513.         case IDOK:
  514.             GetWindowText(GetDlgItem(hwndDlg, IDC_SIDES), str, 255);
  515.       if (g_bDoCone)
  516.               Brush_MakeSidedCone(atoi(str));
  517.       else if (g_bDoSphere)
  518.               Brush_MakeSidedSphere(atoi(str));
  519.       else
  520.               Brush_MakeSided (atoi(str));
  521.  
  522.             EndDialog(hwndDlg, 1);
  523.         break;
  524.  
  525.         case IDCANCEL:
  526.             EndDialog(hwndDlg, 0);
  527.         break;
  528.     }    
  529.     default:
  530.         return FALSE;
  531.     }
  532. }
  533.  
  534.  
  535. void DoSides(bool bCone, bool bSphere, bool bTorus)
  536. {
  537.   g_bDoCone = bCone;
  538.   g_bDoSphere = bSphere;
  539.   //g_bDoTorus = bTorus;
  540.     DialogBox(g_qeglobals.d_hInstance, (char *)IDD_SIDES, g_qeglobals.d_hwndMain, SidesDlgProc);
  541. }        
  542.  
  543.  
  544. //======================================================================
  545.  
  546. /*
  547. ===================
  548. DoAbout
  549. ===================
  550. */
  551. BOOL CALLBACK AboutDlgProc( HWND hwndDlg,
  552.                             UINT uMsg,
  553.                             WPARAM wParam,
  554.                             LPARAM lParam )
  555. {
  556.     switch (uMsg)
  557.     {
  558.     case WM_INITDIALOG:
  559.         {
  560.             char renderer[1024];
  561.             char version[1024];
  562.             char vendor[1024];
  563.             char extensions[4096];
  564.  
  565.             sprintf( renderer, "Renderer:\t%s", qglGetString( GL_RENDERER ) );
  566.             sprintf( version, "Version:\t\t%s", qglGetString( GL_VERSION ) );
  567.             sprintf( vendor, "Vendor:\t\t%s", qglGetString( GL_VENDOR ) );
  568.             sprintf( extensions, "%s", qglGetString( GL_EXTENSIONS ) );
  569.  
  570.             SetWindowText( GetDlgItem( hwndDlg, IDC_ABOUT_GLRENDERER ),   renderer );
  571.             SetWindowText( GetDlgItem( hwndDlg, IDC_ABOUT_GLVERSION ),    version );
  572.             SetWindowText( GetDlgItem( hwndDlg, IDC_ABOUT_GLVENDOR ),     vendor );
  573.             SetWindowText( GetDlgItem( hwndDlg, IDC_ABOUT_GLEXTENSIONS ), extensions );
  574.  
  575.         }
  576.         return TRUE;
  577.  
  578.     case WM_CLOSE:
  579.         EndDialog( hwndDlg, 1 );
  580.         return TRUE;
  581.  
  582.     case WM_COMMAND:
  583.         if ( LOWORD( wParam ) == IDOK )
  584.             EndDialog(hwndDlg, 1);
  585.         return TRUE;
  586.     }
  587.     return FALSE;
  588. }
  589.  
  590. void DoAbout(void)
  591. {
  592.     DialogBox( g_qeglobals.d_hInstance, ( char * ) IDD_ABOUT, g_qeglobals.d_hwndMain, AboutDlgProc );
  593. }
  594.  
  595.  
  596.